package com.soft.dao;

import com.soft.IBaseDao.IBaseDao;
import com.soft.pojo.JobChange;
import com.soft.utils.DBUtil;

import java.util.List;

/**
 * @author ruoxi
 * @create 2021-12-27 10:15
 */
public class JobChangeDaoImpl implements IBaseDao<JobChange> {
    @Override
    public int add(JobChange var1) {
        return 0;
    }

    @Override
    public int del(int var1) {
        return DBUtil.excute("delete from jobchange where eno = ?", var1);
    }

    @Override
    public int update(JobChange var1) {
        return 0;
    }

    @Override
    public List<JobChange> selectByAll() {
        return DBUtil.query("select * from jobchange where state = '1'", JobChange.class);
    }

    @Override
    public JobChange selectByKey(JobChange var1) {
        return null;
    }

    public List<JobChange> selectJobChangeByPage(int currentPage, int currentCount){
        return DBUtil.query("select * from jobchange where state = '1' limit ?,?", JobChange.class, currentPage,currentCount);
    }

    public JobChange selectJobChangeById(int id){
        List<JobChange> jobChanges = DBUtil.query("select * from jobchange where id = ?", JobChange.class, id);
        return jobChanges.get(0);
    }

    public int updateJobChangePassStateByEno(int eno, String afterjob) {
        int excute = DBUtil.excute("update jobchange set state = '0' where eno = ?", eno);
        int excute1 = DBUtil.excute("update emp set job = ? where eno = ?", afterjob, eno);
        return excute+excute1;
    }

    public int updateJobChangeFailStateByEno(int eno) {
        return DBUtil.excute("update jobchange set state = '2' where eno = ?", eno);
    }
}
